package com.xiaolin.structure.stack.array;

/**
 * @ClassName DemoStackTest
 * @Description TODO
 * @Detail detail
 * @Author MyPC
 * @Date 2020/11/6
 * @Version 1.0
 */
public class DemoStackTest {
    public static void main(String[] args) {
        DemoStack<Person> demoStack=new DemoStack<>(10);
        Person p1 = new Person(1);
        Person p2 = new Person(2);
        Person p3 = new Person(3);
        demoStack.push(p1);
        demoStack.push(p2);
        demoStack.push(p3);
//        Person pop1 = demoStack.pop();
//        Person pop2 = demoStack.pop();
//        System.out.println(pop1.getAge());
//        System.out.println(pop2.getAge());
        System.out.println(demoStack.get(1).getAge());
        System.out.println(demoStack.peek().getAge());
        System.out.println(demoStack.isEmpty());

    }

    /**
     * @ClassName Person
     * @Description TODO
     * @Detail detail
     * @Author MyPC
     * @Date 2020/11/6
     * @Version 1.0
     */
    static class Person{
        private int age;

        public Person(int age){
            this.age=age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public int getAge() {
            return age;
        }

        /**
         * 重写equals方法，使他们比较的是age的值
         * @param obj
         * @return
         */
        @Override
        public boolean equals(Object obj) {
            if(obj instanceof Person){
                return this.age==((Person)obj).age;
            }
            return false;
        }
    }
}
